/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.lidejia.xml2pojo.parser;

import com.snda.lidejia.xml2pojo.exception.XMLParserException;
import com.snda.lidejia.xml2pojo.util.ParserArgumentChecker;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Element;
import org.dom4j.Node;

/**
 *
 * @author lidejia
 */
public class XMLListParser implements XMLParser {

    private XMLParserPool pool;

    public XMLListParser(XMLParserPool pool) {
        this.pool = pool;
    }

    public Object parse(Class<?> type, Node... nodes) throws XMLParserException {
        //
        ParserArgumentChecker.checkNotNull(nodes);
        //
        List objects = new ArrayList(nodes.length);
        for (Node node : nodes) {
            XMLParser parser = pool.getParser(type);
            Object object = parser.parse(type, node);
            if (object != null) {
                objects.add(object);
            }
        }
        return objects;
    }
}
